<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ page session="false" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.net.test.vo.TVO" %>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script> 

<script>


	function viewImage(val) {
		var option = {
			url : "/viewImage.ncb",
			type : "post",
			data : $("#writeFrm").serialize(),
			success : function(data) {
				if($.trim(data) == "mimeTypeError"){
					alert("잘못된 형식의 파일을 업로드하고있습니다 꺼져");
					$("#file").remove();
					$("#fileTD").append('<input id="file" type="file" name= "file" style="width:98%;" onchange="javascript: viewImage(this);" />');
					$("#viewIamage").attr("style", "display: none;");
					$("#viewIamage").attr("src", "/");
					return;
				}				
				$("#writeFrm").append('<input type="hidden" name="tempFile" value="'+data+'"" />');
				$("#viewIamage").attr("style", "display: block;");
				$("#viewIamage").attr("src", "/tempUpload/" + data);
			}
		};
		$("#writeFrm").ajaxSubmit(option);
	}
	function go_save() {
		var frm = document.writeFrm;

		//타이틀+컨텐츠 의 입력값이 없으면 return 얼럿때리고~
		if (frm.title.value == "") {
			alert("타이틀 입력해");
			frm.title.focus();
			return;
		}
		if (frm.contents.value == "") {
			alert(" 내용 입력해");
			//frm.contents.focus();
			return;
		}

		if (!confirm("작성하시겠습니까?"))
			return;

		frm.action = "/tboardinsert.ncb";
		frm.submit();

	}
</script>


<% 

	HttpSession session = request.getSession();
	String login_id = (String)session.getAttribute("login_id");
	String login_name = (String)session.getAttribute("login_name");

if(login_id == null || login_id.equals("")){
%>
	<script>
	alert("로그인이 되지 않았습니다. 로그인 페이지로 이동합니다.");
	location.href="/tLogout.ncb";
	</script>
<%
return;
}


String result = request.getAttribute("result") == null ? "" : (String)request.getAttribute("result");

if(result.equals("1")){
%>
	<script>
		alert("글 작성이 됨");
		location.href="/tlogView.ncb";
		//파라미터를 필요하면
	</script>
<%
}else if(!result.equals("") && !result.equals("1")){
%>
	<script>
		alert("에러~");
	</script>
<%
}
%>
<br />
<h1>게시판 글쓰기</h1> 
<br />
<form id="writeFrm" name="writeFrm" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="<%=login_id %>">
	
	
	<table border="1" style="width:650px;">
	
	<%  TVO view = (TVO)request.getAttribute("view"); 
	%>
	
		<tr>
			<td>제목 :</td>
			<td><input type="text" name="title" style="width:98%;" /></td>
		</tr>
		<tr>
			<td>내용 :</td>
			<td><textarea style="width:98%; height:200px;" name="contents"  ></textarea></td>
		</tr>
		<tr>
			<td>파일 등록  :</td>
			<td id="fileTD"><input id="file" type="file" name= "file" style="width:98%;" onchange="javascript: viewImage();" /></td>
		</tr>

		<tr>
			<td>미리보기 :</td>
			<td><img id="viewIamage" alt="" src="" height="250px" style="display: none;"></td>
		</tr>

	</table>
	
	<input type="button" value="등록" onclick="javascript:go_save();" />
	
	
	<br /><br /><br />

</form>






